package com.deu.tsf.common;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class WebContextFilter implements Filter {
	
	private static final Logger logger = LoggerFactory.getLogger(WebContextFilter.class);

	public void destroy() {

	}

	public void doFilter(ServletRequest request, ServletResponse response,FilterChain chain) throws IOException, ServletException {
		
		//设置拦截
		HttpServletResponse resp = (HttpServletResponse) response;
		resp.setHeader("Access-Control-Allow-Origin", "*");
		resp.setHeader("Access-Control-Allow-Headers", "X-Requested-With, Content-Type");
		resp.setHeader("Access-Control-Allow-Credentials", "true");
		resp.setHeader("Access-Control-Allow-Methods", "GET, PUT, POST, DELETE");
//		resp.setHeader("Access-Control-Max-Age", value);
		
		HttpServletRequest req = (HttpServletRequest) request;
		
//		header(': ' . 3600 * 24);
		
//		String requestUri = req.getRequestURI();
//		String contextPath = req.getContextPath();
		
		chain.doFilter(request, response);
	}

	public void init(FilterConfig arg0) throws ServletException {

	}
}
